import request from '@/utils/request'

// 富文本编辑器上传图片 /admin/article/upload
export function uploadImage(file) {
  const formData = new FormData();
  formData.append('file', file[0]);
  return request.post('/admin/article/upload', formData);
}

//添加文章 /admin/article/add
export function addArticle(data) {
  return request({
    url: '/admin/article/add',
    method: 'post',
    data
  })
}

//获取文章列表 /admin/article/list
export function getArticleList(params) {
  return request({
    url: '/admin/article/list',
    method: 'get',
    params
  })
}

//文章置顶 /admin/article/top
export function topArticle(data) {
  return request({
    url: '/admin/article/top',
    method: 'put',
    data
  })
}

//文章推荐 /admin/article/recommend
export function recommendArticle(data) {
  return request({
    url: '/admin/article/recommend',
    method: 'put',
    data
  })
}

//删除文章 /admin/article/delete
export function deleteArticle(data) {
  return request({
    url: '/admin/article/delete',
    method: 'delete',
    data
  })
}

//回收文章（逻辑删除） /admin/article/recycle
export function recycleArticle(data) {
  return request({
    url: '/admin/article/recycle',
    method: 'put',
    data
  })
}

//获取编辑文章信息 /admin/article/edit/{articleId}
export function getEditArticleInfo(articleId) {
  return request({
    url: `/admin/article/edit/${articleId}`,
    method: 'get',
  })
}

//修改文章信息 /admin/article/update
export function updateArticle(data) {
  return request({
    url: '/admin/article/update',
    method: 'put',
    data
  })
}


//获取每天的文章数量
export function getArticleCountDate(year){
  return request({
    url:'/article/countDate',
    method:'get',
    params:{
      year:year
    }
  })
}

//获取热门文章 /article/hot
export function getHotArticle(){
  return request({
    url:'/article/hot',
    method:'get',
  })
}